var tigerManageAd02 = {
	load : function () {
		Ext.QuickTips.init();
		this.eventRegister();
		
		var date = new Date();
		date.setDate(1);
		Ext.getDom("adStartDate").value = date.string();
		
		date.setDate(0);
		date.setMonth(date.getMonth()+1);
		Ext.getDom("adEndDate").value =date.string(); 
		
		new Ext.form.DateField({       
		      applyTo : 'adStartDate',
		      format: 'Y/m/d',       
		      emptyText: '請選擇開始日期 ...' 
		});       
		
		new Ext.form.DateField({       
		      applyTo : 'adEndDate',       
		      format: 'Y/m/d',
		      emptyText: '請選擇結束日期 ...'        
		}); 	
		
		
		var account = getUser().Account;
		
		waitShow();
		Ext.Ajax.request({
			url : "/ad/sys/com/control/AdService.php?action=getAdByAccount&account="+account,
			callback : function (op, sc, resp) {
				waitHide();
				var obj =  resp.responseText.toJSON();
			 
				addOptions("id", [{Id:"all", AdName:"全選"}], "Id", "AdName");
				addOptions("id", obj, "Id", "AdName"); 
			}
		});
	}, 
    eventRegister : function () {
	    Ext.get("download").on('click',this.download);  //確認,新增使用者	
	},
	
	download : function () {
		var adStartDate = Ext.getDom("adStartDate").value;
		var adEndDate = Ext.getDom("adEndDate").value;
		
		if (adStartDate == "請選擇開始日期 ...") {
		 	 alert("請輸入[開始 刊登日期]日期!")
		 	 return;
		}
		 
		if (!adStartDate.isDate()) {
		 	 alert("[開始 刊登日期] 請輸入正確的日期格式!")
		 	 return;
		}
		 
		 
		  if (adEndDate == "請選擇結束日期 ...") {
		 	 alert("請輸入[結束 刊登日期]日期!")
		 	 return;
		 }
		 
		 if (!adEndDate.isDate()) {
		 	 alert("[結束 刊登日期] 請輸入正確的日期格式!")
		 	 return;
		 }
		 
		 if (adStartDate > adEndDate) {
		 	alert("[刊登日期] 區間錯誤!");
		 	return;
		 }
		 
		var url = String.format("/ad/sys/com/control/AdService.php?action=exportExcelMaager&account={0}&id={1}&adBudgetType={2}&adStartDate={3}&adEndDate={4}",
			getUser().Account,
			getOptionValue("id"),
			getOptionValue("adBudgetType"),
			adStartDate,
			adEndDate
		);
		 
	　      window.location = url;
	}
};

Ext.onReady(function (){
	tigerManageAd02.load();
});